/*
 * @Author: zxhuan 
 * @Date: 2017-12-08 15:23:02 
 * @blog: http://www.zxhuan.com 
 * @Last Modified time: 2017-12-08 15:23:02 
 */
/**
 * js的公共函数库
 */
const cookie = {
    setCookie(name, value) {
        var Days = 1;
        var expires = new Date();
        expires.setTime(expires.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + expires.toGMTString();
    },
    /**
     * 获取Cookie函数
     * name:Cookie的名称
     */
    getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) {
            return unescape(arr[2]);
        } else {
            return null;
        }
    },
    /**
     * 删除Cookie
     * @param name
     * 当前时间为失效时间
     */
    delCookie(name) {
        var exp = new Date();  //当前时间  
        exp.setTime(exp.getTime() - 1);
        var cval = cookie.getCookie(name);
        if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();

    }
}
export {
    cookie
};